// view/index/addyuan/addyuan.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
Page({
  /**
   * 页面的初始数据
   */
  ...request,
  data: {
    heights: "",
    title: '修改员工',
    huan: ['健康证', '行业培训从业证'],
    currtab: 0,
    xubian: 0,
    zhiindex: 0, //职位index
    zhilist: [{
      name: '店长',
      id: 2
    }, {
      name: '员工',
      id: 3
    }], //职位
    date: '请选择日期', //开始
    dates: '请选择日期', //结束
    hsjc: '',
    id: '', //修改该员工的id
    xingming: '', //姓名
    dianhua: '', //电话
    shenfenz: '', //身份证号
    zhiweiid: '', //职位id
    qutime: '', //取证时间
    daotime: '', //有效期至
    zhiguo: '请选择职位',
  },
  // 员工详情
  ygxq(e) {
    var that = this
    this.myRequest(yuming + 'shop/shopFindStaff', {
      id: that.data.id,
      shopId: wx.getStorageSync('shopId')
    }, 'POST').then(res => {
      console.log(res)
      var data = res.data.data.result
      that.setData({
        yu: res.data.data.Url,
        xinxi: data,
        xingming: data.Name,
        dianhua: data.Phone,
        shenfenz: data.creatTime,
        zhiweiid: data.creatTime,
        qutime: data.creatTime,
        daotime: data.creatTime
      })
    })
  },
  // 填写姓名
  xingming(e) {
    this.setData({
      xingming: e.detail.value
    })
  },
  // 填写电话
  dianhua(e) {
    this.setData({
      dianhua: e.detail.value
    })
  },
  // 填写身份证
  shenfenz(e) {
    this.setData({
      shenfenz: e.detail.value
    })
  },
  // 生成二维码
  sheng() {
    wx.navigateTo({
      url: '/view/my/xinxilr/xinxilr',
    })
  },
  //点击放大
  fangda(e) {
    var img = e.currentTarget.dataset.img
    wx.previewImage({
      urls: [img]
    })
  },
  chuan(e) {
    console.log(e)
    var aaa = e.currentTarget.dataset.aaa
    var that = this;
    wx.chooseImage({
      count: 1, // 默认9，设置图片张数
      sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
      sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
      success: function (res) {
        var tempFilePaths = res.tempFilePaths
        that.setData({
          hsjc: tempFilePaths
        });
      }
    })
  },
  // 职位
  zhiwei(e) {
    let index = e.detail.value
    this.setData({
      zhiguo: this.data.zhilist[e.detail.value].name,
      zhiweiid: this.data.zhilist[e.detail.value].id
    });
  },
  // 选择开始时间
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value,
      qutime: e.detail.value
    })
  },
  // 选择结束时间
  bindDateChanges: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      dates: e.detail.value,
      daotime: e.detail.value
    })
  },
  // 健康证
  qies(e) {
    var index = e.currentTarget.dataset.currtab
    this.setData({
      currtab: index,
      xubian: 0,
      hsjc: ''
    })
  },
  xubianji() {
    this.setData({
      xubian: 1
    })
  },
  xubaocun() {
    var that = this
    if (wx.getStorageSync('jinghe_id') != 176) {
      urlda = 'shop/shopSaveStaff'
    }
    if (wx.getStorageSync('jinghe_id') != 176) {
      urlda = 'Jinghexincheng/shopSaveStaff'
    }
    this.myRequest(yuming + urlda, {
      id: that.data.id,
      shopId: wx.getStorageSync('shopId'),
      Name: that.data.xingming,
      Phone: that.data.Phone,
      idNumber: that.data.idNumber,
    }, 'POST').then(res => {
      console.log(res)
      var data = res.data.data.result
      that.setData({
        yu: res.data.data.Url,
        xinxi: data,
        xingming: data.Name,
        dianhua: data.Phone,
        shenfenz: data.creatTime,
        zhiweiid: data.creatTime,
        qutime: data.creatTime,
        daotime: data.creatTime
      })
    })
    // this.setData({
    //   xubian: 0
    // })
  },
  // 健康证结束
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      id: options.id
    })
    this.ygxq()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})